home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / DEVEL2.ZIP / RENDER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-13  |  4.0 KB  |  176 lines

  1. /* Written by Bernie Roehl, January 1992 */
  2. /* Redone by Dave Stampe for integer, fast polys, colors etc */
  3. /* Modified by Bernie Roehl to support surface types */
  4.  
  5. /* Contact: broehl@sunee.waterloo.edu or dstampe@sunee.waterloo.edu */
  6.  
  7. #include <stdio.h>
  8. #include <graphics.h>
  9. #include <dos.h>
  10.  
  11. extern int set_colors();        /* defined in color file */
  12. extern int reset_colors();
  13. extern int screen_clear_color;
  14. extern int wireframe_color;
  15. extern int highlight_color;
  16. extern int highest_color;
  17.  
  18.  
  19. enter_graphics()               /* enter and setup graphics screen */
  20. {
  21.     int i;
  22.  
  23.     set_gmode();
  24.     set_vidpage(0,0);
  25.     set_drawpage(0);
  26.     clr_page(0,0);
  27.     set_colors();
  28.  
  29.     return(0);
  30. }
  31.  
  32.  
  33. exit_graphics()            /* exit and restore text screen */
  34. {
  35.     exit_gmode();
  36.     reset_colors();
  37.     return 0;
  38. }
  39.  
  40. void clear_display(int pge)
  41. {
  42.     clr_page(pge,screen_clear_color);
  43. }
  44.  
  45.  
  46. void ppoly(int count, int *xcoords, int *ycoords, int color)
  47.     {
  48.     int x1 = xcoords[0];       /* multisided polys using triangles */
  49.     int y1 = ycoords[0];
  50.     int x2 = xcoords[1];
  51.     int y2 = ycoords[1];
  52.     int x3 = xcoords[2];
  53.     int y3 = ycoords[2];
  54.     int *xp = &xcoords[3];
  55.     int *yp = &ycoords[3];
  56.  
  57.     int surface_type = (color>>12)&3;
  58.     color &= 0xFFF;
  59.     if (surface_type < 2) load_color (color&255);
  60.  
  61.     if (count < 2) return;
  62.     switch (surface_type) {
  63.         case 0:
  64.         case 1: fastri(x1, y1, x2, y2, x3, y3); break;
  65.         case 2: m_fastri(x1, y1, x2, y2, x3, y3, color, 0xFF, 0x00); break;
  66.         case 3: m_fastri(x1, y1, x2, y2, x3, y3, color, 0xAA, 0xFF); break;
  67.         }
  68.     while (count > 3)
  69.         {
  70.         x2 = x3;
  71.         y2 = y3;
  72.         x3 = *xp++;
  73.         y3 = *yp++;
  74.         switch (surface_type) {
  75.             case 0:
  76.             case 1:    fastri(x1, y1, x2, y2, x3, y3); break;
  77.             case 2: m_fastri(x1, y1, x2, y2, x3, y3, color, 0xFF, 0x00); break;
  78.             case 3: m_fastri(x1, y1, x2, y2, x3, y3, color, 0xAA, 0xFF); break;
  79.             }
  80.         count--;
  81.         }
  82.     }
  83.  
  84. /********************************************************/
  85. /* USER ROUTINES CALLED BY THE RENDERING LIBRARY        */
  86. /* KEEP THIS AS FAST AS POSSIBLE: SOME MAY BE           */
  87. /* CALLED UP TO 1000 TIMES PER SCREEN!                  */
  88. /********************************************************/
  89.  
  90. extern int wireframe;
  91.  
  92. /* USER ROUTINE TO SETUP FOR POLY DRAWING - CALLED ONCE PER FRAME */
  93. void user_setup_blitter()
  94. {
  95.     setup_hdwe(0);
  96. }
  97.  
  98. /* USER ROUTINE TO RECOVER AFTER POLY DRAWING: ONCE PER FRAME */
  99. void user_reset_blitter()
  100. {
  101.     reset_hdwe();
  102. }
  103.  
  104.  
  105. /* USER ROUTINE TO DRAW TEXT BOXES */
  106. void user_box(int x1, int y1, int x2, int y2, int color)
  107. {
  108.     setup_hdwe(0);
  109.     load_color(color);
  110.  
  111.     if (x1 < 0) x1 = 0; if (x2 < 0) x2 = 0;
  112.     if (y1 < 0) y1 = 0; if (y2 < 0) y2 = 0;
  113.     if (x1 > 319) x1 = 319; if (x2 > 319) x2 = 319;
  114.     if (y1 > 199) y1 = 199; if (y2 > 199) y2 = 199;
  115.  
  116.     fastri(x1,y1,x1,y2,x2,y1);
  117.     fastri(x2,y2,x2,y1,x1,y2);
  118.     reset_hdwe();
  119. }
  120.  
  121. /* USER ROUTINE TO DRAW TEXT */
  122. void user_text(int x, int y, int color, char *string)
  123. {
  124.     printxyc(x, y, color, string);
  125. }
  126.  
  127.  
  128. static int x1, y1;
  129. static void vlineto(int x, int y, int color)
  130. {
  131.     vgaline(x, y, x1, y1, color);
  132.     x1 = x; y1 = y;
  133. }
  134.  
  135. /* CALLED FROM HIREND TO DRAW POLYS */
  136.  
  137. void user_render_poly(int number, int *xcoords, int *ycoords, int color)
  138. {
  139.     int i;
  140.  
  141.     if (number == 2)
  142.         {
  143.         vgaline(xcoords[0],ycoords[0],xcoords[1],ycoords[1],color);
  144.         return;
  145.         }
  146.     if (!wireframe)
  147.         {
  148.         ppoly(number, xcoords, ycoords, color);
  149.  
  150.         if (color & 0x8000)             /* highlighted? */
  151.             {
  152.             x1 = xcoords[0];
  153.             y1 = ycoords[0];
  154.             for (i = 1; i < number; ++i) vlineto(xcoords[i], ycoords[i], highlight_color);
  155.             vlineto(xcoords[0], ycoords[0], highlight_color);
  156.             }
  157.         }
  158.     else
  159.         {
  160.         x1 = xcoords[0];
  161.         y1 = ycoords[0];
  162.         for (i = 1; i < number; ++i) vlineto(xcoords[i], ycoords[i], wireframe_color);
  163.         vlineto(xcoords[0], ycoords[0], wireframe_color);
  164.         }
  165.     }
  166.  
  167. void vgabox(int left, int top, int right, int bottom, int color)
  168. {
  169.     setup_hdwe(0);
  170.     vgaline(left, top, right, top, color);
  171.     vgaline(right, top, right, bottom, color);
  172.     vgaline(right, bottom, left, bottom, color);
  173.     vgaline(left, bottom, left, top, color);
  174.     reset_hdwe();
  175. }
  176.